package br.unirio.dsw.controle.action;

import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import br.unirio.dsw.controle.dao.DAOFactory;
import br.unirio.dsw.controle.dao.IEstiloDAO;

public class StartupListener implements ServletContextListener {
	
	
	@SuppressWarnings("rawtypes")
	private static List listaEstilos = null;

	@Override
	public void contextDestroyed(ServletContextEvent event) {

		//event.getServletContext().setAttribute("lista", "minha lista boladona");
	}

	@Override
	public void contextInitialized(ServletContextEvent event) {
		try {
			if(listaEstilos == null){
			IEstiloDAO daoEstilo = DAOFactory.getInstance().getEstiloDAO();
			
			String filtro = "WHERE IDSuperEstilo is null";
			
			/**
			 * Recupera os subestilos
			 */
		
			listaEstilos = daoEstilo.consultar(filtro);
			}
			event.getServletContext().setAttribute("lista", listaEstilos);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
	}
}
